package com.itheima.d3_stream;

import java.util.*;
import java.util.stream.Stream;

/*
        目标：掌握Stream流的创建。

        1 单列集合获取Stream流
        2 双列集合获取Stream流
        3 数组获取Stream流
        4 同一种类型多个数据获取Stream流
 */
public class StreamTest2 {
    public static void main(String[] args) {
        // 1、如何获取List集合的Stream流？
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三丰", "张无忌", "周芷若", "赵敏", "张强");
        //单列集合Stream流
        names.stream().forEach(s -> System.out.println(s));
        //双列集合获取Stream流
        HashMap<String, String> map = new HashMap<>();
        map.put("杨过", "小龙女");
        map.put("郭靖", "黄蓉");
        map.put("杨康", "穆念慈");
        Set<Map.Entry<String, String>> entries = map.entrySet();
        entries.stream().forEach(e -> System.out.println(e.getKey() + " " + e.getValue()));

        System.out.println("==================");
//        Set<String> keys = map.keySet();
//        keys.stream().forEach(s -> System.out.print(s + " "));

        //数组获取Stream流
        String[] arr = {"诸葛亮", "徐武", "郭嘉", "张昭"};
        Stream<String> stream = Arrays.stream(arr);
        stream.forEach(s -> System.out.print(s + " "));
        System.out.println();
        //同种类型多个数据的流对象
        Stream<String> stream1 = Stream.of("孙悟空", "红孩儿", "蜘蛛精", "木吒");
        stream1.forEach(s -> System.out.print(s + " "));
    }
}
